Electoral Divisions of Interest

Figure 0.1: Electoral Divisions of Interest

1 🔍 Analysis

1.1 Q1

  1. (3 marks) How many people lived in each electoral division of interest?

The population in Melbourne, Kooyong, Macnamara, Chisholm, Higgins, Goldstein, and Hotham, the electoral divisions, in August, 2016 as calculated from the 2016 Australian Census Data provided by Australian Bureau of Statistics(ABS), and the 2019 Australian Elections Data from Australian Election Commission is provided below in 1.1.

Table 1.1: Electoral Division Population
Elect_div population
Melbourne 188086
Hotham 174920
Chisholm 170550
Macnamara 167054
Higgins 158330
Kooyong 155264
Goldstein 147656
Electoral Division Population

Figure 1.1: Electoral Division Population

Electoral Division Population

Figure 1.2: Electoral Division Population

Electoral Division Population

Figure 1.3: Electoral Division Population

1.2 Q2

  1. (6 marks) Show the age distribution (omitting those 80 years old or greater) of each electoral division of interest by plotting a barplot like below. State three interesting observations regarding the plot below with a possible reason why you see such observations using knowledge about the electoral division (if you do not know, search the internet to find out).

The age distribution is shown in the bar plot below 1.4.

## `summarise()` has grouped output by 'Elect_div'. You can override using the `.groups` argument.
Age Distribution in Electoral Divisions

Figure 1.4: Age Distribution in Electoral Divisions

We can see that the median ages for the electoral divisions in consideration is is one of 35, 40, 34, 36, and 29. In Melbourne, we see a spike in the bar graph in the age distributions 20 to 40 and all other age groups are significantly lower, with a very few old aged people residing there. Also, people above 40 contribute to less than 5% of the Melbourne’s population. Goldstein, however, has the majority group between 40 to 60 and has the highest median age. The overall trend is similar for all constituents with older age groups gradually reducing in number. From the map below, we see that in Hotham, there are dark color boxes which suggest a younger popopulation. It is our own Monash University Clayton Campus!!!. Generally, the population is younger around the universities in Victoria. A light coloured irregular polygon can be seen in Hotham, probably suggesting an old age home.
Spatial Age Distribution

Figure 1.5: Spatial Age Distribution

Spatial Age Distribution

Figure 1.6: Spatial Age Distribution

1.3 Q3

  1. (4 marks) What are the percentages of Australian citizens for each electoral division of interest? Why do you think the percentage of Australian citizens is lower for Melbourne, Hotham and Macnamara?
The maps below, 1.7 display the the percentages of Australian citizens in each electoral division and the the cloropeth map displays the total population in the Australian electoral divisions. We observe that the percentage share of Australian citizens is lower in Melbourne, Hotham and Macnamara. This may be because of the following reasons: - Melbourne City is located in Melbourne division, a metropolitan and developed city is a home to people from all over the world- tourism, education, jobs, and businesses attracting people from all over the world. - In Hotham, Monash University is situated which is itself has around 30,000 international students enrolled. - Macnamara is the a coastal boundary, which may have famous beaches and ports, again an to attraction to foreign individuals. Many Tourists might have been present on the census night.
Australian Citizen Percentage Share

Figure 1.7: Australian Citizen Percentage Share

1.4 Q4

  1. (4 marks) What is an estimate of adult (i.e. aged 18 years old or over) Australian citizens in each electoral division of interest? State your assumptions for your estimate.

An estimate of Australian citizens is provided in based on the G09 table from the datapacks of Austrlian Bureau of Statistics. The Assumption here is that:

  • All people born in Australia are Australian citizens.
  • All people not born in Australia are not Australian citizens.
  • All people born in 2016 are 18 and above on May, 2019; that is during the federal elections.

The Actual column represents the actual voters(adult australian citizens) in each election division(Election Data Shape File) .The difference is because of the assumptions that we make and all other types of citizenship attainment are also not considered!

(#tab:adultaustralian citizens)Adult Population Estimate
Elect_div adult_aus_citizen_population Actual australian_citizens population
Chisholm 65624 106409 125734 170550
Goldstein 73236 106548 123744 147656
Higgins 76519 108550 122026 158330
Hotham 56852 107479 126983 174920
Kooyong 76897 107353 125556 155264
Macnamara 74758 110119 118207 167054
Melbourne 69886 104982 108357 188086

1.5 Q5

  1. (5 marks) The political members would like to know the composition of ethnic background of their constituents. Show the top 10 reported ancestry for each electoral division of interest with an appropriate graph. State one interesting observation from your graph.

We see from the following table and the graph that:

  • In Chisholm, the Chinese are more prevelant than Australians themselves.
  • The English and Australian ethnic groups are comparable in all divisons.
  • Many people have not stated their ancestries.
Table 1.2: Top10 Ancestries
Melbourne Kooyong Macnamara Chisholm Higgins Goldstein Hotham
English English English Chinese English English Chinese
Chinese Aust Aust English Aust Aust English
Aust Chinese Other Aust Irish Irish Other
Other Irish Irish Other Other Other Aust
Ancestry_NS Scottish Ancestry_NS Irish Chinese Scottish Greek
Irish Other Scottish Scottish Scottish Ancestry_NS Indian
Scottish Italian Chinese Indian Ancestry_NS Chinese Italian
Italian Ancestry_NS Italian Ancestry_NS Greek Italian Irish
Indian Greek German Greek Italian Greek Ancestry_NS
German Indian Greek Italian Indian German Scottish
Top 10 Ancestries

Figure 1.8: Top 10 Ancestries

1.6 Q6

  1. (4 marks) What are the distribution of religious background in each electoral district of interest? Show this by using a plot. Report one interesting observation from what you see.

“The Australian Standard Classification of Religious Groups (ASCRG) has a three level hierarchical structure that consists of broad groups, narrow groups and religious groups.” ~ ABS

Here, the narrow classification is used to include sikkhism, other religions and Australian Aboriginal Traditional religion. One interesting oservation is that a significant number of people do not have any religious affiliation which is highest in Melbourne.Christianity is a widespread religion in these divisions and more so across Australia.

Religious Distribution

Figure 1.9: Religious Distribution

1.7 Q7

  1. (4 marks) What are the level of the highest qualification the person has completed for each electoral division of interest? State one interesting observation with a possible explanation of that observation.

The education level distribution according to the narrow classification as described in Australian Standard Classification of Education (ASCED), 2001 is shown in figure 1.3.

## `summarise()` has grouped output by 'Elect_div'. You can override using the `.groups` argument.
ASCED Education Level Distribution

Figure 1.10: ASCED Education Level Distribution

Table 1.3: ASCED Education Level Distribution
educationlevel Chisholm Goldstein Higgins Hotham Kooyong Macnamara Melbourne
AdvDip_and_Dip 14077.00 12578.00 12319.0 13473.0 11388.00 13463.00 12509.00
BachDeg 34001.00 31751.00 41460.0 29030.0 39060.00 43659.00 52222.00
Cert_I_II 693.00 590.00 547.0 849.0 488.00 634.00 721.00
Cert_III_IV 11456.00 9680.00 8705.0 14183.0 7216.00 10687.00 8563.00
Cert_Levl_nfd 2076.00 2005.00 1761.0 1985.0 1646.00 1953.00 1620.00
GradDip_and_GradCert 4603.00 4660.00 5270.0 3059.0 5609.00 5483.00 5533.00
Lev_Edu_IDes 1291.00 1058.00 1145.0 1426.0 1185.00 1259.00 1349.00
Lev_Edu_NS 9650.00 8687.00 10834.0 11085.0 8723.00 17042.00 20360.00
PGrad 13855.00 11214.00 15636.0 11262.0 15951.00 16628.00 20730.00
NA 42059.07 36305.17 37512.5 43526.8 38717.37 40600.62 37401.59

The distribution according to the Australian Qualification Framework is shown below.

## `summarise()` has grouped output by 'Elect_div'. You can override using the `.groups` argument.

1.8 Q8

List your data file names that you used here. 8. (2 marks) List all data used for the analysis (including its file name). Do not include any unused dataset.

Files from Australian Census Data used with file structure:

  • Data Packages
    • data/2016 Census GCP All Geographies for VIC/SA1/VIC/
      • 2016Census_G01_VIC_SA1.csv #question1,3
      • 2016Census_G04A_VIC_SA1.csv #question2
      • 2016Census_G04B_VIC_SA1.csv #question2
      • 2016Census_G09F_VIC_SA1.csv #question4
      • 2016Census_G08_VIC_SA1.csv #question5
      • 2016Census_G14_VIC_SA1.csv #question6
      • 2016Census_G46B_VIC_SA1.csv #question7
    • Procedure to download
      • go to Census GeoPackages
      • select /2016 Census Datapacks in Step 1: Select Census year
      • select /General Community Profile in Step 2: Select DataPacks type
      • select /All geographies in Step 3: Select Geography
      • Download the zip file under Vic.
  • GeoPackages
    • data/census2016_cldb_vic_short.gpkg

    • Procedure to download

      • go to Census GeoPackages
      • select /Victoria in Step 1: Select State or Territory
      • select /Cultural and Language Diversity (CLD) in Step 2: Select Topic
      • select /CLD GeoPackage B in Step 3: Select GeoPackage
      • Download the zip file.
  • Election Data Shape File

1.9 Code

knitr::opts_chunk$set(echo = FALSE, 
                      messages = FALSE, 
                      warning = FALSE, fig.path = "Data/Figures", fig.align ="center")
library(tidyverse)
library(sf)
library(glue)
library(unglue)
library(readr)
library(sugarbag)
library(kableExtra)
knitr::write_bib(c(.packages()), "packages.bib")
data_path <- here::here("data/")
path <-  glue::glue(data_path, "australian_{source}_data_{year}/", 
                    source = c("election", "census"), year = c("2019", "2016"))
election_paths <- glue::glue(data_path, "/House{file}Download-24310.csv", 
                        file = c("DopByDivision","MembersElected"))
census_paths <- glue::glue(data_path, "2016 Census GCP All Geographies for VIC/SA1/VIC/2016Census_G{number}{alpha}_VIC_SA1.csv", 
                         number = c("01","04","04","09","09","09","09","09","09","08","14","46","46"), alpha = c("","A","B","A","B","C","D","E","F","","","A","B"))
vic_map_path <- glue::glue(data_path, "/vic-july-2018-esri/E_AUGFN3_region.shp")
#vic_map_path <- glue::glue(data_path, "E_AUGFN3_region.shp")
constituents <- c("Melbourne","Kooyong","Macnamara","Chisholm","Higgins","Goldstein","Hotham")
vic_map <- read_sf(vic_map_path) %>% filter(Elect_div %in% constituents)
geopath <- glue::glue(data_path, "census2016_cldb_vic_short.gpkg")
geomap <- function(df){
  df %>% 
          mutate(centroid = map(geom, st_centroid),
                centroid = st_as_sfc(centroid, crs = st_crs(vic_map)),
                which = as.integer(st_intersects(centroid, vic_map)),
                Elect_div = ifelse(is.na(which),
                "None",
                vic_map$Elect_div[which])) %>%
      filter(Elect_div %in% constituents) %>%
                select(sa1_7digitcode_2016, Elect_div, centroid) %>% 
       unnest_wider(centroid) 

    
  }
sa1_geomap <- map_dfr(geopath, ~{
                              layer <- data.frame(name = st_layers(.x)["name"])
                              df <- read_sf(.x, layer = layer$name[6], 
                                            stringsAsFactors = FALSE)
                              geomap(df)
                            })

sa1_regions <- data.frame(SA1_7DIGITCODE_2016=as.character(sa1_geomap$sa1_7digitcode_2016), Elect_div = sa1_geomap$Elect_div)

vic_mapcentroid <- vic_map  %>% 
          mutate(centroid = map(geometry, ~setNames(st_centroid(.x), c("x", "y"))),
                centroid = st_as_sfc(centroid, crs = st_crs(vic_map))) %>%
   unnest_wider(centroid) 
election_data_raw <- read_csv(election_paths[1], skip=1)
elected_members <- read_csv(election_paths[2])
vic_map %>%
  ggplot() +
  geom_sf(mapping = aes(geometry= geometry, fill=Elect_div))+
  geom_sf_text(aes(geometry= geometry,label=Elect_div, colour="#000000")) +
  theme_void() +
  theme(legend.position = "none")

clean_G01_G04_G09 <- function(df) {
  
   df %>% 
     pivot_longer(cols = -c(SA1_7DIGITCODE_2016,Elect_div), 
                  names_to = "category",
                  values_to = "count") %>% 
    filter(str_detect(category, "Age_yr_\\d+_P|Australian_citizen_P|Tot_P_P|P_Australia_[0-9]+_[0-9]+|P_Australia_85ov|[A-Za-z_]+_Tot_Resp") | !str_detect(category,"Australia_Tot")) %>%
      unglue_unnest(category, 
                   c( "{citizenship=Australian}_citizen_P", 
                      "Age_yr_{age=\\d+}_P",
                      "{sex=[MF]}_{population=Tot}_Tot",
                      "P_{population=Australia}_{age_min=\\d+}_{age_max=\\d+}",
                    "P_{population=Australia}_{age_min=85}ov",
                    "{ancestry=[A-Za-z]+|[A-Za-z]+_Abor|[A-Za-z]+_Lankan|[A-Za-z]+_African|[A-Za-z]+_NS}_Tot_Resp"
                      ),
                   remove = FALSE) %>% 
      mutate(across(starts_with("age"), as.numeric))
      
}
sa1_g01 <- map_dfr(census_paths[1], ~{
                df <- read_csv(.x) %>% 
                  mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>%
                  select(Australian_citizen_P,Tot_P_P,SA1_7DIGITCODE_2016) %>%
                  right_join(sa1_geomap,
                             by=c("SA1_7DIGITCODE_2016"="sa1_7digitcode_2016")) %>%
                                    select(Australian_citizen_P,Tot_P_P,SA1_7DIGITCODE_2016, Elect_div)

                clean_G01_G04_G09(df)
                })

count_people_constituent <- sa1_g01 %>% 
                             group_by(Elect_div) %>% 
                              filter(is.na(citizenship)) %>% 
                                summarise(population=sum(count)) %>%
                                arrange(desc(population))

knitr::kable(count_people_constituent, caption = "Electoral Division Population") %>% 
    kable_styling(bootstrap_options = "striped", "hover", "bordered", full_width = F, position = "center")%>%
    kable_classic_2()
  
count_people_constituent%>%
  ggplot(mapping = aes(x=reorder(Elect_div, population), y= population, fill = Elect_div)) +
  geom_col() +
  scale_y_continuous(labels = scales::comma) +
  coord_flip()+ labs(x="Population", y="Electoral Division")


count_people_constituent <- count_people_constituent %>% left_join(vic_mapcentroid, by=c("Elect_div"="Elect_div")) 

count_people_constituent %>%
  ggplot() +
  geom_sf(mapping = aes(geometry= geometry, fill=population)) +
  geom_sf_text(aes(geometry= geometry,label=Elect_div, colour="white"))

count_people_constituent %>%
  ggplot() +
  geom_sf(mapping = aes(geometry= geometry, fill=Elect_div)) +
  geom_sf_text(aes(geometry= geometry,label=population))+
  theme_void() +
  theme(legend.position = "none")

sa1_g04 <- map_dfr(census_paths[2:3], ~{
                df <- read_csv(.x) %>% 
                  mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>% 
                  select(all_of(matches("Age_yr_[0-9]+_P")),SA1_7DIGITCODE_2016)%>%
                  inner_join(sa1_regions,
                             by=c("SA1_7DIGITCODE_2016"="SA1_7DIGITCODE_2016"))
                clean_G01_G04_G09(df)
                })

population <- sa1_g04 %>% 
      group_by(Elect_div) %>%
  summarise(population_division = sum(count)) %>%
                                arrange(desc(population_division))
sa1_g04 %>% 
      group_by(Elect_div, age) %>%
  summarise(populationbyage = sum(count)) %>% 
  left_join(population, by = c("Elect_div"="Elect_div")) %>% 
  mutate(percentage=populationbyage/population_division*100) %>% 
        ggplot() +
  geom_col(mapping = aes(x = age, y = percentage))+
  facet_grid(Elect_div~.)

sa1_g04map <- sa1_g04 %>% left_join(sa1_geomap ,by=c("SA1_7DIGITCODE_2016"="sa1_7digitcode_2016", "Elect_div"="Elect_div"))
sa1_g04mapmedian <- sa1_g04map[rep(rownames(sa1_g04map), sa1_g04map$count), ]

medianage <- sa1_g04mapmedian %>% select(age, SA1_7DIGITCODE_2016, Elect_div)
sa1region_medianage <- medianage  %>% 
     group_by(SA1_7DIGITCODE_2016) %>%
  summarise(sa1region_medianage = median(age))
   
electdiv_medianage <- medianage  %>% 
     group_by(Elect_div) %>%
  summarise(electdiv_medianage = median(age))

sa1_medianage_g04map <- sa1_g04map %>% left_join(sa1region_medianage) %>%
  left_join(electdiv_medianage)

ggplot(sa1_medianage_g04map) +
  geom_sf(aes(geometry = geom, fill = sa1region_medianage)) + 
 geom_sf(data = vic_map, aes(geometry = geometry), fill = "transparent", size = 1.3, color = "black") +
 scale_fill_viridis_c(name = "Median age", option = "magma")+
  theme_void() +
  labs(title = "Median Age in SA1 Regions")
ggplot(sa1_medianage_g04map) +
  geom_sf(aes(geometry = geom, fill = electdiv_medianage)) + 
 geom_sf(data = vic_map, aes(geometry = geometry), fill = "transparent", size = 1.3, color = "black") +
 scale_fill_viridis_c(name = "Median age", option = "magma")+
  theme_void() +
  labs(title = "Median Age in Electoral divisions")
count_people_constituent <- sa1_g01 %>% 
   group_by(Elect_div) %>% 
      filter(citizenship == "Australian") %>% 
         summarise(australian_citizens=sum(count)) %>% 
            left_join(count_people_constituent, by = c("Elect_div"="Elect_div")) %>% 
                mutate(percentage=(australian_citizens/population)*100) %>%
                  arrange(desc(percentage)) 
people_table <- count_people_constituent %>% select(Elect_div,australian_citizens,population,Area_SqKm,Actual,Projected,percentage)
count_people_constituent %>%
  ggplot() +
  geom_sf(mapping = aes(geometry= geometry, fill=australian_citizens)) +
  geom_sf_text(aes(geometry= geometry,label=percentage, colour="red")) +
  labs(title = "Australian Citizen Percentage")+
  theme_void() 
count_people_constituent %>%
  ggplot() +
  geom_sf(mapping = aes(geometry= geometry, fill=Elect_div)) +
  geom_sf_text(aes(geometry= geometry,label=population))+
  labs(title = "Total Population")+
  theme_void() 

sa1_g09_population <- map_dfr(census_paths[9], ~{
                df <- read_csv(.x) %>% 
                  mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>% 
                   select(all_of(matches("P_Australia_[0-9]+_[0-9]+")),SA1_7DIGITCODE_2016,P_Australia_85ov)%>%
                  right_join(sa1_geomap,
                             by=c("SA1_7DIGITCODE_2016" = "sa1_7digitcode_2016")) %>%
                   select(all_of(matches("P_Australia_[0-9]+_[0-9]+")),SA1_7DIGITCODE_2016,P_Australia_85ov,Elect_div)
      
                clean_G01_G04_G09(df)
                })
sa1_g09_aus_citizen_population_count <- sa1_g09_population %>% 
  filter((age_min != 0) & (age_min != 5)) %>%
     group_by(Elect_div) %>% 
         summarise(adult_aus_citizen_population=sum(count)) %>% 
  left_join(people_table, by = c("Elect_div"="Elect_div")) 
 
# estimate adult_aus_citizen_population-c+d (c is 15-17 year olds, d is other australian citizens)

knitr::kable(sa1_g09_aus_citizen_population_count%>%select(Elect_div, adult_aus_citizen_population,Actual, australian_citizens, population), caption = "Adult Population Estimate") %>% 
    kable_styling(bootstrap_options = "striped", "hover", "bordered", full_width = F, position = "center")
  
sa1_ethnic_background <- map_dfr(census_paths[10], ~{
                df <- read_csv(.x) %>% 
                  mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>% 
                  select(ends_with("_Tot_Resp"), SA1_7DIGITCODE_2016) %>%
                  select(- Tot_P_Tot_Resp) %>%  
                  right_join(sa1_regions,
                             by=c("SA1_7DIGITCODE_2016" = "SA1_7DIGITCODE_2016"))
                clean_G01_G04_G09(df)
                })
anscestry_count <- data.frame(ancestry=NA, Elect_div=NA, population=NA)
for (i in constituents) {
  temp <- sa1_ethnic_background  %>% 
    filter(Elect_div==i) %>%
   group_by(ancestry, Elect_div) %>%
    summarise(population = sum(count)) %>%
      ungroup() %>% 
    arrange(desc(population)) %>%
     head(10)
   anscestry_count <- rbind(anscestry_count,temp)
}
anscestry_count <- anscestry_count[-1,]
anscestry_count_table <- anscestry_count%>%pivot_wider(names_from = Elect_div, values_from= ancestry) 
tableanscestry<- function(x) {
     sa1_ethnic_background %>%
       filter(Elect_div == x)%>%
       group_by(ancestry) %>%
    summarise(population = sum(count)) %>%
    arrange(desc(population)) %>%
     head(10)%>%
       select(-population)

   }
   
    Melb<- tableanscestry(constituents[1]) 
    
    Koo<- tableanscestry(constituents[2])
    Mac<- tableanscestry(constituents[3]) 
    
    Chi<- tableanscestry(constituents[4])
    
    Hig<- tableanscestry(constituents[5])
    
    Gol<- tableanscestry(constituents[6]) 
    
    Hoth<- tableanscestry(constituents[7])
     
    
    
    anscestrytable<- Melb %>% 
      mutate(Melb)%>% rename(Melbourne = ancestry) %>%
      mutate(Koo)%>% rename(Kooyong = ancestry) %>%
      mutate(Mac)%>% rename(Macnamara = ancestry) %>%
      mutate(Chi)%>% rename(Chisholm = ancestry) %>%
      mutate(Hig)%>% rename(Higgins = ancestry) %>%
      mutate(Gol)%>% rename(Goldstein = ancestry) %>%
      mutate(Hoth) %>% rename(Hotham = ancestry)

    
anscestry_count_redundant <- anscestry_count[rep(rownames(anscestry_count), anscestry_count$population), ]


knitr::kable(anscestrytable, caption = "Top10 Ancestries") %>% 
    kable_styling(bootstrap_options = "striped", "hover", "bordered", full_width = F, position = "center")

anscestry_count_redundant %>% 
    ggplot() +
     geom_count(mapping = aes(x=Elect_div,y=ancestry)) +
  labs(y = "Ancestry", x = "Electoral Divison") 


clean_G14 <- function(df) {
  
   df %>% 
    group_by(SA1_7DIGITCODE_2016) %>% 
     pivot_longer(cols = -c(SA1_7DIGITCODE_2016,Elect_div,geom),
                  names_to = "category",
                  values_to = "count") %>%
    filter(str_detect(category,"Christianity_Tot_P")| str_detect(category,"[A-Z]([a-z]+)_P")| str_detect(category,"NRA_Tot_P") | str_detect(category,"ns_P")| str_detect(category,"reln_groups_P")) %>%
    filter(!str_detect(category,"Christianity_|Christnty_|Christinty_|^Tot_|^Other")|str_detect(category,"Christianity_Tot_P"))%>% 
    unglue_unnest(category, 
                    c("{religion=Christianity}_Tot_P",
                      "{religion=[A-Za-z]+}_P",
                      "Othr_Rel_{religion=Aust_Abor_Trad_Rel|Sikhism}_P",
                    "{religion=Othr}_Reln_Other_reln_groups_P",
                    "SB_OSB_{religion=NRA}_Tot_P",
                    "Religious_affiliation_{religion=ns}_P"
                    ),
                   remove = FALSE)
}
sa1_religious_background <- map_dfr(census_paths[11], ~{
                df <- read_csv(.x) %>% 
                  mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>% 
                  right_join(sa1_geomap,
                             by=c("SA1_7DIGITCODE_2016" = "sa1_7digitcode_2016")) 
                clean_G14(df)
                })

sa1_religious_background <- sa1_religious_background %>% 
  mutate(religion=case_when(str_detect(religion, "Othr") ~ "Other",
                            str_detect(religion, "NRA") ~ "No Religious Affiliation",
                            str_detect(religion, "ns") ~ "Not Stated",
                            str_detect(religion, "Aust_Abor_Trad_Rel") ~ "Aboriginal",
                            TRUE ~ religion))

sa1_religious_background %>% 
      group_by(Elect_div, religion) %>%
  summarise(populationbyreligion = sum(count)) %>% 
        ggplot() +
  geom_col(mapping = aes(x = religion, y = populationbyreligion))+
  facet_grid(Elect_div~.) + 
  theme(axis.text.x = element_text(angle=45))+ labs( title = "Religious Distribution")
g46b<- read_csv(census_paths[13]) %>%
  select(P_PGrad_Deg_Total,
P_GradDip_and_GradCert_Total,
P_BachDeg_Total,
P_AdvDip_and_Dip_Total,
P_Cert_III_IV_Total,
P_Cert_I_II_Total,
P_Cert_Levl_nfd_Total,
P_Lev_Edu_IDes_Total,
P_Lev_Edu_NS_Total,SA1_7DIGITCODE_2016) %>%
            mutate(SA1_7DIGITCODE_2016 = as.character(SA1_7DIGITCODE_2016)) %>% 
   right_join(sa1_geomap,
              by=c("SA1_7DIGITCODE_2016" = "sa1_7digitcode_2016")) %>%
  pivot_longer(cols = -c(SA1_7DIGITCODE_2016,Elect_div,geom),
                  names_to = "category",
                  values_to = "count") %>%
  unglue_unnest(category, 
                    c("P_{educationlevel=GradDip_and_GradCert}_Total",
                      "P_{educationlevel=PGrad}_Deg_Total",
                      "P_{educationlevel=BachDeg}_Total",
                      "P_{educationlevel=AdvDip_and_Dip}_Total",
                      "P_{educationlevel=Cert_III_IV}_Total",
                      "P_{educationlevel=Cert_I_II}_Total",
                      "P_{educationlevel=Cert_Levl_nfd}_Total",
                      "P_{educationlevel=Lev_Edu_IDes}_Total",
                      "P_{educationlevel=Lev_Edu_NS}_Total"
                      ),
                remove = FALSE)
  
g46b <- g46b %>% 
  mutate(afq_level =case_when(str_detect(educationlevel, "GradDip_and_GradCert") ~ "Level 8",
                            str_detect(educationlevel, "PGrad") ~ "Level 9",
                            str_detect(educationlevel, "BachDeg") ~ "Level 7",
                            str_detect(educationlevel, "AdvDip_and_Dip") ~ "Level 5 & 6",
                            str_detect(educationlevel, "Cert_III_IV") ~ "Level 3 & 4",
                            str_detect(educationlevel, "Cert_I_II") ~ "Level 1 & 2",
                            str_detect(educationlevel, "Cert_Levl_nfd") ~ "Level 3 & 4",
                            str_detect(educationlevel, "Lev_Edu_IDes") ~ "Level Inadequately Described",
                            str_detect(educationlevel, "Lev_Edu_NS") ~ "Not Stated",
                            TRUE ~ educationlevel))
asced <- g46b %>% 
      group_by(Elect_div, educationlevel) %>%
  summarise(populationbyeducation = sum(count)) 
#g46bredundant <- g46b[rep(rownames(g46b), g46b$count), ]

# g46bredundant%>% 
#         ggplot() +
#   geom_count(mapping = aes(x = Elect_div, y = educationlevel))+labs(title = "Population Distribution by AESCED Education Levels", x="Electoral Divisions", y="AESCED Education Level")

asced%>%ggplot() +
  geom_col(mapping = aes(x = educationlevel, y = populationbyeducation))+
  facet_grid(Elect_div~.) + 
  theme(axis.text.x = element_text(angle=45))+labs(title = "Population Distribution by AESCED Education Levels", x="Electoral Divisions", y="AESCED Education Level")


  
  knitr::kable(asced%>%pivot_wider(names_from = Elect_div,values_from =populationbyeducation ), caption = "ASCED Education Level Distribution") %>% 
    kable_styling(bootstrap_options = "striped", "hover", "bordered", full_width = F, position = "center")
asced <- g46b %>% 
      group_by(Elect_div, educationlevel,SA1_7DIGITCODE_2016) %>%
  summarise(populationbyeducation = sum(count)) 
oneobs <- sa1_geomap%>%slice(c(1,2,3,4,7,19,16))
asced <- asced%>%left_join(sa1_geomap, by=c("Elect_div"="Elect_div", "SA1_7DIGITCODE_2016"="sa1_7digitcode_2016"))

ggplot(asced) +
   geom_point(aes(`...3`, `...4`, fill=populationbyeducation), shape = 3) + 
   geom_sf(data = vic_map, aes(geometry = geometry), fill = "transparent", size = 1.3, color = "black")
g46b %>% 
      group_by(Elect_div, afq_level) %>%
  summarise(populationbyeducation = sum(count)) %>% 
        ggplot() +
  geom_col(mapping = aes(x = afq_level, y = populationbyeducation))+
  facet_grid(Elect_div~.) + 
  theme(axis.text.x = element_text(angle=45)) +
  labs(title = "AFQ Level of Education", y = "Population")

1.10 Resources

1.10.1 R Packages

These R packages have been used to build this report.

R Core Team (2021) Wickham et al. (2021) Wickham (2021a) Wickham et al. (2020) Hester (2020) Zhu (2021) Henry and Wickham (2020) Wickham and Hester (2020) Pebesma (2021) Wickham (2019) Kobakian and Cook (2020) Müller and Wickham (2021) Wickham (2021b) Wickham (2021c) Fabri (2020) Wickham (2016) Pebesma (2018) Kobakian and Cook (2019) Wickham et al. (2019)

1.10.2 Data Sources

1.10.3 R Packages

<>

Fabri, Antoine. 2020. Unglue: Extract Matched Substrings Using a Pattern. https://CRAN.R-project.org/package=unglue.
Henry, Lionel, and Hadley Wickham. 2020. Purrr: Functional Programming Tools. https://CRAN.R-project.org/package=purrr.
Hester, Jim. 2020. Glue: Interpreted String Literals. https://CRAN.R-project.org/package=glue.
Kobakian, Stephanie, and Dianne Cook. 2019. “Sugarbag: Create Hexagon Tile Maps.” https://srkobakian.github.io/sugarbag/.
———. 2020. Sugarbag: Create Tessellated Hexagon Maps. https://CRAN.R-project.org/package=sugarbag.
Müller, Kirill, and Hadley Wickham. 2021. Tibble: Simple Data Frames. https://CRAN.R-project.org/package=tibble.
Pebesma, Edzer. 2018. Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal 10 (1): 439–46. https://doi.org/10.32614/RJ-2018-009.
———. 2021. Sf: Simple Features for r. https://CRAN.R-project.org/package=sf.
R Core Team. 2021. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Wickham, Hadley. 2016. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. https://ggplot2.tidyverse.org.
———. 2019. Stringr: Simple, Consistent Wrappers for Common String Operations. https://CRAN.R-project.org/package=stringr.
———. 2021a. Forcats: Tools for Working with Categorical Variables (Factors). https://CRAN.R-project.org/package=forcats.
———. 2021b. Tidyr: Tidy Messy Data. https://CRAN.R-project.org/package=tidyr.
———. 2021c. Tidyverse: Easily Install and Load the Tidyverse. https://CRAN.R-project.org/package=tidyverse.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.
Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, and Dewey Dunnington. 2020. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://CRAN.R-project.org/package=ggplot2.
Wickham, Hadley, Romain François, Lionel Henry, and Kirill Müller. 2021. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Wickham, Hadley, and Jim Hester. 2020. Readr: Read Rectangular Text Data. https://CRAN.R-project.org/package=readr.
Zhu, Hao. 2021. kableExtra: Construct Complex Table with Kable and Pipe Syntax. https://CRAN.R-project.org/package=kableExtra.